<template>
  <div id="app">
    <vue-progress-bar />
    <router-view />
  </div>
</template>

<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import store from "@/store";

@Component
export default class App extends Vue {
  /** 播报计时器 */
  timer = null;

  mounted() {
    store.dispatch("global/initSocket");
  }

  clearTimer() {
    clearInterval(this.timer);
    this.timer = null;
  }

  /**
   * 轮询
   */
  // TODO暂时从缓存里直接取 后续优化
  training() {
    return new Promise(resolve => {
      try {
        const { shopInfoVo } = JSON.parse(
          window.localStorage.getItem("userInfo"),
        );
        this.timer = setInterval(() => {
          clearInterval(this.timer);
          resolve(shopInfoVo.shopId);
        }, 1000);
      } catch (err) {
        return null;
      }
    });
  }
}
</script>

